const router = require('express').Router();
const bannerService = require('../../service/banner');

/**
 * @apiDefine Banner  横幅
 */

/**
 * @api {get} /v1/banner/list  获取横幅
 * @apiVersion 1.0.0
 * @apiName GetBannerList
 * @apiGroup  Banner
 *
 * @apiDescription 获取横幅
 *
 * @apiExample Example usage:
 * curl -i http://localhost:3502/v1/banner/list
 *
 * @apiSuccess {Number} code      请求结果编码，0：正常， 其他为异常
 * @apiSuccess {string} message    请求结果编码对应的message
 * @apiSuccess {Object[]} data    返回值数据
 * @apiSuccess {Object[]} data.list  数组
 * @apiSuccess {number} data.list.id  标记Id
 * @apiSuccess {string} data.list.imageUrl  图片地址
 * @apiSuccess {number} data.list.status  状态
 *
 * @apiSuccessExample 正常响应：
 *     HTTP/1.1 200
 {
    "code": 200,
    "message": "请求成功",
    "data": {
        "list": [
            {
                "id": 2,
                "imageUrl": "http:",
                "status": 1
            }
        ]
    }
}
 *
 *
 * @apiError  ServerError  服务器异常
 *
 * @apiErrorExample Response (example):
 *     HTTP/1.1 500 ServerError
 *     {
 *       "code": 500,
 *       "message": "服务器异常"
 *     }
 */
router.get('/list', (req, res, next) => {
  bannerService.getList()
    .then((data) => res.success({ list: data }))
    .catch(e => next(e))
});

module.exports = router;
